/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package ua.kiev.gcore.net.command
{
	import flash.utils.ByteArray;
	import flash.utils.Endian;

	public class CommandBuilderBase
	{	
		
		public function build(commandInfo:CommandInfo):Command
		{
			
			var buffer:ByteArray = new ByteArray();
			buffer.endian = Endian.LITTLE_ENDIAN;
			
			var packageData:ByteArray = new ByteArray();
			packageData.endian = Endian.LITTLE_ENDIAN;
			
			packageData.writeInt(commandInfo.commandType);
			packageData.writeInt(commandInfo.commandId);
			
			packageData.writeBytes(commandInfo.command);
			
			buffer.writeInt(packageData.length);
			buffer.writeBytes(packageData);
			
			return new Command(commandInfo.adress, commandInfo.port, buffer, Command.BYTEARRAY);
		}
	}
}